import Vue from 'vue'
import Router from 'vue-router'
import register from './views/register.vue'
import login from './views/login.vue'
import userInfo from './views/userInfo.vue'
import edit from './views/edit.vue'
import home from './views/home.vue'
import article from './views/article.vue'
// import editcategory from './views/EditCategory.vue'
const editcategory = () => import('@/views/EditCategory.vue')


Vue.use(Router)





export default new Router({
  routes: [
    {
      path: '/',
      redirect: "/home"
    },

    {
      path: '/register',
      component: register
    },
    {
      path: '/login',
      component: login
    },
    {
      path: '/userInfo',
      component: userInfo
    },
    {
      path: '/edit',
      component: edit
    },
    {
      path: '/home',
      component: home,
      meta: {
        keepalive: true
      }
    },
    {
      path: '/article/:id',
      component: article,
      meta: {
        keepalive: true
      }
    },
    {
      path: '/editcategory',
      component: editcategory
    },


  ]
})


/* mata:{
        istoken:true
      }

// Router.addRoutes(Route)
Router.forEach((to,form,next)=>{
  //在每个路由跳转之前打印要跳转的路由的信息
  // console.log(to);

  //如果Router跳转之前都有用户的 id,token 的话，才能够进行下一步的跳转。
  if(!localStorage.getItem('id') && !localStorage.getItem('token') && to.meta.istoken===true){
    router.push('login')
    vue.prototype.$msg.fail("请重新登录")
    return
  }
  next()

}) */





